# -*- coding: utf-8 -*-#
#-------------------------------------------------------------------------------
# 建立者:        黄周云  
# Name:         test14_4
# Description:  例14.4
# Author:       ASUS
# Date:         2019/4/17
#-------------------------------------------------------------------------------


import json
data = {
    'name':'Bill',
    'company':'Microsoft',
    'age':34
}
#将字典转换为json字符串
jsonStr = json.dumps(data)
print(type(jsonStr))
print(jsonStr)
#将json字符串转换为字典
data = json.loads(jsonStr)
print(type(data))
print(data)

#定义一个json字符串
s = '''
{
"name":"Bill",
"company":"Microsoft",
"age":34
}
'''
#使用eval函数将json字符串转化为字典
data = eval(s)
print(type(data))
print(data)


f = open('files/products.json','r',encoding='utf-8')
jsonStr = f.read()
json1 = json.loads(jsonStr)
print(json1)
print(json1[0]['name'])

